home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / Demos / images / datfilt.awk < prev    next >
Text File  |  1996-10-04  |  2KB  |  124 lines

  1. BEGIN {
  2.     for (t=1; t<ARGC; t++)
  3.     {
  4.     fin=ARGV[t];
  5.     name=fin;
  6.     sub(/\..*$/,"",name);
  7.     fout=name ".h"
  8.     getline colors < fin;
  9.  
  10.     depth=0;
  11.     bit=1;
  12.  
  13.     while (bit < length(colors))
  14.     {
  15.         depth++;
  16.         bit*=2;
  17.     }
  18.  
  19.     height=0;
  20.     width=0;
  21.     while ((getline line < fin) > 0)
  22.     {
  23.         pattern[height++] = line;
  24.         if (length(line)>width)
  25.         width=length(line);
  26.     }
  27.  
  28.     printf ("Processing %s -> %s (%d x %d x %d)\n", fin, fout, width, height, depth);
  29.  
  30.     for (y=0; y<height; y++)
  31.     {
  32.         line=pattern[y];
  33.         xoff=0;
  34.  
  35.         while (line!="")
  36.         {
  37.         for (d=0; d<depth; d++)
  38.             out[y,xoff,d]=0;
  39.  
  40.         left=substr(line,1,16);
  41.         line=substr(line,17);
  42.         bit=32768;
  43.  
  44.         for (x=1; x<=16; x++)
  45.         {
  46.             cpen=substr(left,x,1);
  47.  
  48.             if (cpen=="")
  49.             break;
  50.  
  51.             pen=index(colors,cpen);
  52.             if (!pen)
  53.             {
  54.             printf ("Error: Unknown pen '%s' in file in line %d\n", cpen, y+2);
  55.             exit 10;
  56.             }
  57.  
  58.             pen --;
  59.  
  60.             for (d=0; d<depth; d++)
  61.             {
  62.             if (pen/2.0 != int(pen/2.0))
  63.             {
  64. #printf ("Pos: %d/%d Plane:%d %04x\n", y, xoff, d, bit);
  65.                 out[y,xoff,d]+=bit;
  66.             }
  67.             pen=int(pen/2);
  68.             }
  69.  
  70.             bit=bit/2;
  71.         }
  72.  
  73.         xoff ++;
  74.         }
  75.     }
  76.  
  77.     printf ("") > fout;
  78.  
  79.     NAME=toupper(name);
  80.     printf ("#define %s_WIDTH    %d\n", NAME, width) >> fout;
  81.     printf ("#define %s_HEIGHT   %d\n\n", NAME, height) >> fout;
  82.  
  83.     printf ("UWORD %sData[] =\n", name) >> fout;
  84.     printf ("{\n") >> fout;
  85.     xmax=int((width+15)/16);
  86.     pick=0;
  87.     bit=1;
  88.     for (d=0; d<depth; d++)
  89.     {
  90.         pick+=bit;
  91.         bit=bit*2;
  92.         for (y=0; y<height; y++)
  93.         {
  94.         printf ("   ") >> fout;
  95.  
  96.         for (x=0; x<xmax; x++)
  97.         {
  98.             printf (" 0x%04X,", out[y,x,d]) >> fout;
  99.         }
  100.  
  101.         printf ("\n") >> fout;
  102.         }
  103.  
  104.         if (d+1!=depth)
  105.         printf ("\n") >> fout;
  106.     }
  107.     printf ("};\n\n") >> fout;
  108.  
  109.  
  110.     printf ("struct Image %sImage =\n{\n", name) >> fout;
  111.     printf ("    0, 0, /* Left, Top */\n") >> fout;
  112.     printf ("    %s_WIDTH, %s_HEIGHT, /* Width, Height */\n", NAME, NAME) >> fout;
  113.     printf ("    %d, /* Depth */\n", depth) >> fout;
  114.     printf ("    %sData, /* ImageData */\n", name) >> fout;
  115.     printf ("    0x%02X, /* PlanePick */\n", pick) >> fout;
  116.     printf ("    0x00, /* PlaneOnOff */\n") >> fout;
  117.     printf ("    NULL /* NextImage */\n") >> fout;
  118.     printf ("};\n") >> fout;
  119.  
  120.     close (fin);
  121.     close (fout);
  122.     }
  123. }
  124.